import fs from 'node:fs';

const files = fs.readdirSync('./plugins/LNERobot/src/apps').filter(file => file.endsWith('.js'));

let ret = [];

files.forEach((file) => {
  ret.push(import(`./src/apps/${file}`));
});

ret = await Promise.allSettled(ret);

let apps = {};
logger.info(`----------------------`);
logger.info(`LNE开始加载`);
for (let i in files) {
  let name = files[i].replace('.js', '');
  logger.info(`加载子插件 ${name}`);

  if (ret[i].status != 'fulfilled') {
    logger.error(`载入插件错误：${logger.red(name)}`);
    logger.error(ret[i].reason);
    continue;
  }
  apps[name] = ret[i].value[Object.keys(ret[i].value)[0]];
}
logger.info(`LNE加载完成`);
logger.info(`-----------------------`);
export { apps };
